<template>
  <div class="newsysDictContainer">
    <div
      class="dialog animated"
      :class="open? 'fadeIn':'fadeOut'"
      v-show="show"
      :style="{visibility: (visible?'visible':'hidden')}"
    >
      <div class="panel animated" :class="open? 'zoomIn':''">
        <div class="title">
          {{title}}
          <div class="close" @click="cancel()"></div>
        </div>
        <div>
          <el-form label-width="140px">
            <el-form-item label="类型" :rules="[
      { required: true, message: ''}]">
              <el-input
                ref="remark"
                style="width:50%"
                clearable
                v-model="sysDictData.remark"
                placeholder="请输入数据字典类型"
              ></el-input>
            </el-form-item>
            <el-form-item label="名称" :rules="[
      { required: true, message: ''}]">
              <el-input
                ref="name"
                style="width:50%"
                clearable
                v-model="sysDictData.name"
                placeholder="请输入名称"
              ></el-input>
            </el-form-item>
            <el-form-item label="数据值" :rules="[
      { required: true, message: ''}]">
              <el-input
                ref="dicValue"
                style="width:50%"
                clearable
                v-model="sysDictData.dicValue"
                placeholder="请输入数据字典的值"
              ></el-input>
            </el-form-item>
            <el-form-item label="数据键" :rules="[
      { required: true, message: ''}]">
              <el-input
                ref="dicKey"
                style="width:50%"
                clearable
                v-model="sysDictData.dicKey"
                placeholder="请输入数据字典的键"
              ></el-input>
            </el-form-item>
            <el-form-item label="排序号" :rules="[
      { required: true, message: ''}]">
              <el-input
                ref="orderBy"
                style="width:50%"
                clearable
                v-model="sysDictData.orderBy"
                placeholder="请输入数据字典版本号，默认为1.0"
              ></el-input>
            </el-form-item>
            <el-form-item label="版本号" :rules="[
      { required: true, message: ''}]">
              <el-input
                ref="version"
                style="width:50%"
                clearable
                v-model="sysDictData.version"
                placeholder="请输入数据字典版本号，默认为1.0"
              ></el-input>
            </el-form-item>
          </el-form>
          
        </div>
        <div class="btn_div">
          <div class="btn_sure" @click="sure()">确 认</div>
          <div class="btn_cancel" @click="cancel()">取 消</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
var vm;
export default {
  data: function() {
    return {
      show: false,
      open: false,
      visible: false,
      title: "",
      sysDictData: {}
    };
  },
  methods: {
    init: function(data) {
      vm.show = true;
      setTimeout(function() {
        vm.open = true;
        vm.visible = true;
      }, 11);
      vm.title = "修改数据字典";
      vm.sysDictData = data;
    },
    sure: function() {
      var rules = [];
      let remark = this.$refs.remark;
      let name = this.$refs.name;
      let dicValue = this.$refs.dicValue;
      let orderBy = this.$refs.orderBy;
      let dicKey = this.$refs.dicKey;
      let version = this.$refs.version;
      vm.sysDictData.version =
        vm.sysDictData.version == "" ? "1.0" : vm.sysDictData.version;
      rules.push({
        judge: vm.sysDictData.remark,
        focus: remark,
        tips: "请输入类型"
      });
      rules.push({
        judge: vm.sysDictData.dicKey,
        focus: dicKey,
        tips: "请输入数据键"
      });
      rules.push({
        judge: vm.sysDictData.version,
        focus: version,
        tips: "请输入版本号"
      });
      rules.push({
        judge: vm.sysDictData.name,
        focus: name,
        tips: "请输入名称"
      });
      rules.push({
        judge: vm.sysDictData.dicValue,
        focus: dicValue,
        tips: "请输入数据值"
      });
      rules.push({
        judge: vm.sysDictData.orderBy,
        focus: orderBy,
        tips: "请输入排序号"
      });
      if (!tool.validate(rules)) {
        return;
      }
      api.sysdictUpdate(vm.sysDictData).then(function(data) {
        if (data.resultCode == 2000) {
          vm.$message({
            message: "编辑成功",
            type: "success"
          });
          vm.$emit("callback", "");
          vm.cancel();
        } else {
          vm.$message.error(data.message);
        }
      });
    },
    cancel: function() {
      //隐藏弹窗
      vm.open = false;
      setTimeout(function() {
        vm.show = false;
        vm.visible = false;
      }, 500);
    }
  },
  created: function() {
    vm = this;
  }
};
</script>
<style lang="scss">
.newsysDictContainer {
  .line_from {
    height: 1px;
    margin: 0.24rem 0.18rem 0.18rem 0.18rem;
    background-color: #f3f6fc;
  }
  .el-form--inline .el-form-item {
    vertical-align: inherit;
  }
}
</style>
<style scoped src="@/style/clue_manage/clue_add.css"></style>
<style scoped src="@/style/module/dialog.css"></style>
<style scoped>
.panel {
  width: 8rem;
  padding-bottom: 0.2rem;
}
</style>

